home *** CD-ROM | disk | FTP | other *** search
/ Programmers Heaven 2 / Programmers Heaven 2.iso / files / graphics / library / wgt51_r2.zip / WGT5 / EXAMPLES / WGT02.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  3.2 KB  |  87 lines

  1. /*
  2. ==============================================================================
  3.                       WordUp Graphics Toolkit Version 5.0
  4.                              Demonstration Program 2                          
  5.                                                                               
  6.  Draws pixels with a random colour in random places until you hit a key.      
  7.                                                                               
  8.  The second loop fills the screen with wfastputpixel.                         
  9.                                                                               
  10.  The third third loop reads in the pixels in the top left corner of the        
  11.  screen with wgetpixel and uses wputpixel to recreate the image in            
  12.  the bottom right corner.                                                     
  13.                                                                               
  14.  *** PROJECT ***                                                             
  15.  This program requires the file WGT5_WC.LIB to be linked.                    
  16.                                                                               
  17.  *** DATA FILES ***                                                          
  18.  NONE                                                                        
  19.                                                            WATCOM C++ VERSION 
  20. ==============================================================================
  21. */
  22.  
  23. #include <wgt5.h>
  24.  
  25. void main(void)
  26. {
  27.   short x;
  28.   short y;
  29.   short i;
  30.   short oldmode;
  31.  
  32.   printf ("WGT Example #2\n\n");
  33.   printf ("This program will draw random pixels until you hit a key.\n");
  34.   printf ("Then it will fill the screen using wfastputpixel, press a key.\n");
  35.   printf ("The wgetpixel command is then used to duplicate a portion of the screen.\n");
  36.   printf ("\n\nPress any key to continue.\n");
  37.   getch ();
  38.  
  39.   if ( !vgadetected() )
  40.   {
  41.     printf("Error - VGA card required for any WGT program.\n");
  42.     exit(0);
  43.   }
  44.  
  45.   oldmode = wgetmode();         /* Gets the current mode        */
  46.   vga256();                     /* Initializes WGT system       */
  47.   wcls(0);                      /* Clear screen with color 0    */
  48.  
  49.   /* Put randomly coloured pixels in random screen coordinates  */
  50.   do {
  51.     wsetcolor(rand() % 255);
  52.     x = rand() % 320;
  53.     y = rand() % 200;
  54.     wputpixel(x,y);
  55.   } while (kbhit()==0);
  56.   getch();
  57.  
  58.   wcls(0);                      /* Clear screen with color 0    */
  59.   wsetcolor(10);                /* Now we will draw with #10    */
  60.   for (x = 0; x < 320; x++)
  61.     for (y = 0; y < 200; y++)
  62.       wfastputpixel(x,y);       /* Fast due to no clipping checking */
  63.  
  64.   getch();
  65.   wcls(0);                      /* Clears screen with color 0   */
  66.  
  67.   /* Put randomly coloured pixels in the top left corner of the screen  */
  68.   for (i = 0; i < 15000; i++)
  69.   {
  70.     wsetcolor(rand() % 256);
  71.     x = rand() % 160;
  72.     y = rand() % 100;
  73.     wputpixel(x,y);
  74.   }
  75.  
  76.   /* Now use wgetpixel to read image off screen */
  77.   for (y = 0; y < 100; y++)
  78.     for (x = 0; x < 160; x++)
  79.     {
  80.       wsetcolor(wgetpixel(x,y));
  81.       wputpixel(x + 160,y + 100);
  82.     }
  83.  
  84.   getch();
  85.   wsetmode(oldmode);            /* Restore old video mode       */
  86. }
  87.